package com.afinal.intelligencetrash.ui.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;


import com.afinal.intelligencetrash.Model.bean.Message;
import com.afinal.intelligencetrash.R;

import java.util.List;

/**
 * Created by 厂里帅小伙 on 2/18 0018.
 */

public class MessageListAdapter extends RecyclerView.Adapter<MessageListAdapter.ViewHolder> {

    private List<Message> dateList = null;

    public void setDateList(List<Message> dateList) {
        this.dateList = dateList;
        notifyDataSetChanged();
    }

    static class ViewHolder extends RecyclerView.ViewHolder{
         TextView tv_notify_time;
         TextView tv_notify_content;
        public ViewHolder(View itemView) {
            super(itemView);
            tv_notify_time = (TextView) itemView.findViewById(R.id.tv_notify_time);
            tv_notify_content = (TextView) itemView.findViewById(R.id.tv_notify_content);
        }
    }

    public MessageListAdapter(){

    }
    public MessageListAdapter(List<Message> dateList) {
        this.dateList = dateList;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.message_item_layout, parent, false);
        ViewHolder viewHolder = new ViewHolder(view);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        holder.tv_notify_time.setText(dateList.get(position).getLocalTime());
        holder.tv_notify_content.setText(dateList.get(position).getContent());
    }

    @Override
    public int getItemCount() {
        return dateList == null? 0 : dateList.size();
    }
}
